<template>
	<view>
		<view class="btn-box">
			<view class="btn" @tap="show=false">
				修改用户信息
			</view>
		</view>
		
		<view class="a main" v-if="show">
			<view class="box">
				<view class="left">
					<view class="text">
						头像
					</view>
				</view>
				<view class="right">
					<image :src="userInfo.icon" mode=""></image>
				</view>
			</view>
			<view class="box">
				<view class="left">
					<view class="text">
						用户名
					</view>
					
				</view>
				<view class="right">
					{{userInfo.username}}
				</view>
			</view>
			<view class="box">
				<view class="left">
					
					<view class="text">
						昵称
					</view>
				</view>
				<view class="right">
					{{userInfo.nickname}}
				</view>
			</view>
			<view class="box">
				<view class="left">
					<view class="text">
						手机号
					</view>
				</view>
				<view class="right">
					{{userInfo.phone}}
				</view>
			</view>
			
			<view class="out" @tap="out()">
				退出登录
			</view>
			
		</view>
		<view class="b main" v-else>
			<view class="box">
				<view class="left">
					<view class="text">
						头像
					</view>
				</view>
				<view class="right uptx">
					<view class="btn1" @tap="updateimg()" v-if="!txshow">
						上传头像
					</view>
					<image :src="imgUrl" mode="" @tap="updateimg()" v-else></image>
				</view>
			</view>
			<view class="box">
				<view class="left">
					<view class="text">
						用户名
					</view>
					
				</view>
				<view class="right">
					<!-- {{info.username}} -->
					<input type="text" value="" v-model="userInfo.username" />
				</view>
			</view>
			<view class="box">
				<view class="left">
					
					<view class="text">
						昵称
					</view>
				</view>
				<view class="right">
					<!-- {{info.nickname}} -->
					<input type="text" value="" v-model="userInfo.nickname" />
				</view>
			</view>
			<view class="box">
				<view class="left">
					<view class="text">
						手机号
					</view>
				</view>
				<view class="right">
					<!-- {{info.phone}} -->
					<input type="text" value="" v-model="userInfo.phone" />
				</view>
			</view>
			
			<view class="update" @tap="gx()">
				更新
			</view>
		</view>
	</view>
</template>

<script>
	
	import baseUrl from "@/api/baseUrl.js"
	import { getMemberInfo,updateMemberInfo } from "../../api/mine/mine.js";
	export default {
		data() {
			return {
				userInfo:{},
				show:true,
				txshow:false,
				imgUrl:'../../static/icons/QQ.png'
			}
		},
		
		onLoad() {
			// var info = uni.getStorageSync("userInfo");
			// this.info = info;
			getMemberInfo().then(res=>{
				console.log(res)
				this.userInfo = res.data.userInfo;
				console.log(this.userInfo)
			})
		},
		methods: {
			out(){
				uni.clearStorage();
				uni.switchTab({
					url:"/pages/mine/mine"
				})
			},
			gx(){
				updateMemberInfo(this.userInfo).then(res=>{
					console.log(res);
				})
				this.out()
			},
			
			updateimg(){
				var _this = this;
				uni.chooseImage({
					count:1,
					sizeType:['original','compressed'],
					success(res){
						// console.log(res)
						var files = res.tempFilePaths[0];
						uni.uploadFile({
							url:baseUrl + "/lejuClient/login/uploadAvatar",
							filePath:files,
							name:"file",
							success(res1){
								console.log(res1);
								_this.imgUrl = JSON.parse(res1.data).data.fileUrl;
								_this.txshow = true;
								_this.userInfo.icon = _this.imgUrl
							}
						})
					}
				})
			}
			
			
		}
	}
</script>

<style lang="scss" scoped>
	.btn-box{
		display: flex;
		justify-content: flex-end;
		padding: 15rpx 20rpx;
		.btn{
			width: 226rpx;
			height: 60rpx;
			text-align: center;
			font-size: 30rpx;
			line-height: 60rpx;
			border: 2rpx solid rgba(0,0,0,.6);
			border-radius: 10rpx;
		}
	}
	.uptx{
		image{
			width: 120rpx;
			height: 120rpx;
			border-radius: 50%;
		}
	}
	.main{
		padding: 0 30rpx;
		image{
			width: 120rpx;
			height: 120rpx;
			border-radius: 50%;
		}
		.box{
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 40rpx 0;
			color: #a1a1a1;;
			border-bottom: 2rpx solid #E9E7E6;
		}
	}
	.b .box{
		color: #000;
		.btn1{
			width: 174rpx;
			height: 60rpx;
			text-align: center;
			font-size: 30rpx;
			line-height: 60rpx;
			border: 2rpx solid rgba(0,0,0,.6);
			border-radius: 10rpx;
			
			
		}
	}
	
	.out,
	.update
	{
		width: 370rpx;
		height: 88rpx;
		text-align: center;
		line-height: 88rpx;
		border-radius: 10rpx;
		background-color: #354e44;
		color: #fff;
		margin: 500rpx auto;
	}
	
	input{
		text-align: right;
	}
	
	
	
</style>
